#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <climits>
#include <queue>

using namespace std;

int main(int argc, char const *argv[])
{
    string arr[64];
    int n, m, i, j, k, l, wt, bt, rt, w[64], b[64], r[64];
    int temp, result;
    cin >> n >> m;
    getchar();
    for (i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    for (i = 0; i < n; i++)
    {
        wt = bt = rt = m;
        for (j = 0; j < m; j++)
        {
            if (arr[i][j] == 'W') wt--;
            if (arr[i][j] == 'B') bt--;
            if (arr[i][j] == 'R') rt--;
        }
        w[i] = wt;
        b[i] = bt;
        r[i] = rt;
    }
    result = INT_MAX;
    for (i = 1; i <= n - 2; i++)
    {
        for (j = 1; j <= n - i - 1; j++)
        {
            // printf("%d %d %d\n", i, j, n - i - j);
            temp = 0;
            for (k = 0; k < i; k++)
            {
                temp += w[k];
            }
            for (k = i; k < i + j; k++)
            {
                temp += b[k];
            }
            for (k = i + j; k < n; k++)
            {
                temp += r[k];
            }
            result = min(temp, result);
            // cout << temp << "\n";
        }
    }
    cout << result;
    return 0;
}
